package com.hanhanxiaochong.zhongxiangchuanmei.view.home.act;

import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.util.Utils;
import com.jakewharton.rxbinding.view.RxView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Description:
 * Created by RockPhoenixHIAPAD on 2018/1/12 on 14:05.
 */

public class ContactUsDialogFragment extends DialogFragment {

    @BindView(R.id.tv_phone_number)
    TextView tvPhoneNumber;
    @BindView(R.id.tv_call)
    TextView tvCall;

    private Unbinder unbinder;

    public static ContactUsDialogFragment newInstance(String phone_number) {
        ContactUsDialogFragment fragment = new ContactUsDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString("phone_number", phone_number);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        final Dialog dialog = new Dialog(getActivity(), R.style.ContactDialogStyle);
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
        dialog.setContentView(R.layout.dialog_contact_us);
        unbinder = ButterKnife.bind(this, dialog);
        initView();
        return dialog;
    }

    private void initView() {
        String phone_number = getArguments().getString("phone_number");
        tvPhoneNumber.setText(phone_number);
        RxView.clicks(tvCall)
                .subscribe(o -> {
                    Utils.callPhone(getActivity(), tvPhoneNumber.getText().toString().trim());
                    dismiss();
                });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
